<?php

// @formatter:off
/**
 * @file WCSearchFactory.php
 *
 * @author Alejandro Dario Simi
 * @date $Date: 2014-05-04 01:33:52 +0000 (Sun, 04 May 2014) $
 *
 * $Id: WCSearchFactory.php 111 2014-05-04 01:33:52Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/includes/search/WCSearchFactory.php $
 */
// @formatter:on
/**
 * @class WCSearchFactory 
 */
class WCSearchFactory extends WCFactory {
	//
	// Protected class properties.
	protected static $_Builders = false;
	//
	// Public class methods.
	public static function ItemBuilder(WCSearchResult &$template) {
		$out = false;

		self::RegisterBuilders();

		if(isset(self::$_Builders[$template->type()])) {
			$out = self::$_Builders[$template->type()]->item($template->id());
		}

		return $out;
	}
	public static function Types() {
		self::RegisterBuilders();
		return array_keys(self::$_Builders);
	}
	//
	// Protected class methods.
	protected static function RegisterBuilders() {
		if(self::$_Builders === false) {
			self::$_Builders = array();

			global $wcSearchHolders;
			foreach($wcSearchHolders as $holderName) {
				if(method_exists($holderName, "Instance")) {
					eval("\$holder = {$holderName}::Instance();");

					if(!$holder instanceof WCSearchIndexableHolder) {
						continue;
					}

					$type = substr(strtoupper($holder->searchItemsType()), 0, 2);

					self::$_Builders[$type] = $holder;
				}
			}
		}
	}
}
